package org.douxiaoban.client.widget;

import org.douxiaoban.client.R;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;

import org.douxiaoban.client.app.Assistant;
import org.douxiaoban.client.widget.ElasticListView.ParentView;

public class ElasticLayout extends LinearLayout implements ParentView{
	Context mContext;
	ImageView mImageView;
	View mUpdateView;
	ElasticListView mListView;
	public ElasticLayout(Context context) {
		super(context);
		mContext = context;
		// TODO Auto-generated constructor stub
		initLayout();
	}
	
	public ElasticLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		initLayout();
	}
	
	//
	private void initLayout(){
		
		this.setOrientation(VERTICAL);
		mImageView = new ImageView(mContext);
	//	mImageView.setBackgroundDrawable(mContext.getResources().getDrawable(id));
		
		LayoutParams imageParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		mImageView.setBackgroundResource(R.drawable.down_arrow);
		mImageView.setLayoutParams(imageParams);
		//mImageView.setVisibility(View.GONE);
		LayoutInflater flater = LayoutInflater.from(mContext);
		
		mUpdateView = flater.inflate(R.layout.foot, null);
		mUpdateView.setVisibility(View.GONE);
		
		LayoutParams listParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		mListView = new ElasticListView(mContext);
		mListView.setLayoutParams(listParams);
		mListView.setParent(this);
		this.addView(mUpdateView);
		this.addView(mImageView);
		this.addView(mListView);
		
		//this.layout(0, -mImageView.getHeight(), getWidth(), getHeight());		
	}
	
	@Override
	public void dispatchDraw(Canvas canvas){
		canvas.translate(0, -mImageView.getHeight());
		super.dispatchDraw(canvas);
	}
	
//	@Override
//	public void onLayout(boolean bool, int l, int t, int r, int b){
//		
//	}
	public ListView getListView(){
		return mListView;
	}
	
	public void changeStatus(int status){
		if(Assistant.UN_NEED_UPDATE == status){
			
		}else if(Assistant.NEED_UPDATE == status){
			mUpdateView.setVisibility(View.VISIBLE);
		}
	}
}

